<?php
require_once(dirname(__FILE__) . "/start.inc");
global $CONFIG;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>A/B Tester - </title>
	<?php include("views/html_includes.php");?>
	<script type="text/javascript">
		$(document).ready(function(){

			$("#ab-dialog").dialog({
                autoOpen : true,
                height : 300,
                width : 500,
                modal : true,
                resizable : false,
                open : function(event, ui) {
                    //$('#html-editor').val($(opts.element).outerHtml());
                    $('.ui-dialog, .ui-dialog *, .ui-widget-overlay').bind('click', function(event) {
                        event.preventDefault();
                        event.stopPropagation();
                        return false;
                    });
                },
                buttons : {
                    "OK" : function(event) {
                        // TODO: check if changed
                        var changed = true;
                        if (changed) {
                            // save the change
                            var editor = $.abTester.editor();
                            var result = editor.update($('#html-editor').val(), $selectedElement);
                            $(result, opts.currentWindow.document).children().overlay();
                        }
                        //
                        $(this).dialog('close');
                        // remove selected
                        $.unOverlay(opts);
                    },
                    "Cancel" : function(event) {
                        event.stopPropagation();
                        $(this).dialog('close');

                        // remove selected
                        $.unOverlay(opts);
                    }
                },
                close : function(event) {
                    // close the dialog
                    event.stopPropagation();

                    // remove selected
                    $.unOverlay(opts);
                }
            });

		});
	</script>
</head>
<body>
<div id="wrapper">
	<div id="header"></div>
		<div id="main">
			<div id='ab-dialog' style="display: none;">
			<div class="edit-html pane" style="display: block;">
				<p>Enter HTML to replace the selected element.</p>
				<textarea id="html-editor" cols="68" rows="7"></textarea>
			</div>
		</div>
	</div>
    <div id="footer"></div>
</div>
</body>
</html>